package com.chj;


import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * SpringBoot应用集成Prometheus, 提供上报Metrics
 * 访问地址：http://localhost:8080/actuator/prometheus
 *
 * Prometheus 配置：
 *
 * scrape_configs:
 *   # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
 *   - job_name: 'prometheus'
 *
 *     # metrics_path defaults to '/metrics'
 *     # scheme defaults to 'http'.
 *
 *     static_configs:
 *     - targets: ['localhost:9090']
 *
 *   - job_name: 'springboot-prometheus-exporter-dmeo'
 *     metrics_path: '/actuator/prometheus'
 *     scrape_interval: 5s
 *     static_configs:
 *     - targets: ['127.0.0.1:8080']
 *
 */
@SpringBootApplication
public class SpringbootExporterDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootExporterDemoApplication.class, args);
    }

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(
            @Value("${spring.application.name}") String applicationName) {
        return (registry) -> registry.config().commonTags("application", applicationName);
    }
}

